#include <iostream>
#include <vector>

/**
 * PAT A 1021 Deepest Root
 */

struct Vertex {
    std::vector<int> edges;
    int parent;
    int maxDepth;

    Vertex(int index) : parent(index), maxDepth(0) {}
};

std::vector<Vertex> vertices;

int find(int idx) {
    Vertex &vert = vertices[idx];
    if (vert.parent != idx)
        vert.parent = find(vert.parent);
    return vert.parent;
}

void Union(int i1, int i2) {
    int r1 = find(i1);
    int r2 = find(i2);
    vertices[r2].parent = r1;
}

void search(int last, int cur, int len) {
    Vertex &vert = vertices[cur];
    vert.maxDepth = std::max(vert.maxDepth, len);
    for (int i = 0; i < vert.edges.size(); i++) {
        int to = vert.edges[i];
        if (to == last)
            continue; // avoid infinite recursion
        search(cur, to, len + 1);
    }
}

int main() {
    // Read graph and compute connected components
    int num;
    scanf("%d", &num);
    vertices.reserve(num);
    for (int i = 0; i < num; i++)
        vertices.push_back(Vertex(i));
    for (int i = 0; i < num - 1; i++) {
        int from, to;
        scanf("%d %d", &from, &to);
        from--; // convert to 0-indexed
        to--;
        vertices[from].edges.push_back(to);
        vertices[to].edges.push_back(from);
        Union(from, to);
    }

    // Check number of components
    int nComp = 0;
    for (int i = 0; i < num; i++)
        if (find(i) == i)
            nComp++;
    if (nComp > 1) {
        printf("Error: %d components\n", nComp);
        return 0;
    }

    // Perform DFS starting from each leaf
    for (int i = 0; i < num; i++) {
        Vertex &vert = vertices[i];
        if (vert.edges.size() != 1)
            continue;
        search(-1, i, 0);
    }

    // Collect deepest roots
    int maxDepth = 0;
    std::vector<int> results;
    for (int i = 0; i < num; i++) {
        Vertex &vert = vertices[i];
        if (vert.maxDepth > maxDepth) {
            results.clear();
            results.push_back(i);
            maxDepth = vert.maxDepth;
        } else if (vert.maxDepth == maxDepth)
            results.push_back(i);
    }
    for (int i = 0; i < results.size(); i++)
        printf("%d\n", results[i] + 1);

    return 0;
}